﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.Location;
using MVC_System.DTO.Reservoir;
using MVC_System.DTO.Warehouse;
using Newtonsoft.Json;
using WMS_MAV;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;

namespace MVC_System.Controllers
{
    public class WarehousesController : Controller
    {
        protected readonly IConfiguration _configuration;

        public WarehousesController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        /// <summary>
        /// 仓库显示
        /// </summary>
        /// <returns></returns>
        public IActionResult warehouseShow()
        {
            return View();
        }
        /// <summary>
        /// 仓库显示API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfowarehouseShow(warehouseShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"]+ "mhb/api/Warehouse/WarehouseShow?pageiden=" + dto.pageindex + "&pageSzen=" + dto.pagesize + "&warehouseNumber=" + dto.warehouseNumber + "&positionNumber=" + dto.positionNumber + "&warehouseState=" + dto.warehouseState;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }

        /// <summary>
        /// 仓库添加
        /// </summary>
        /// <returns></returns>
        public IActionResult warehouseADD()
        {
            return View();
        }
        /// <summary>
        /// 仓库添加API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfowarehouseADD(warehouseADDDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"]+ "mhb/api/Warehouse/WarehouseAdd";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 平面图显示
        /// </summary>
        /// <returns></returns>
        public IActionResult PrincipalShow()
        {
            return View();
        }
        /// <summary>
        /// 库区显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ReservoirShow()
        {
            return View();
        }
        /// <summary>
        /// 库区管理显示列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> ReservoirShowsj(ReservoirDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Values/ShowReservoir?pageIndex=" + dto.pageIndex + "&pageSize=" + dto.pageSize + "&reservoirName=" + dto.reservoirName + "&reservoirNumber=" + dto.reservoirNumber;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 添加库区管理
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> ReservoirAdd(ReservoirAddDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Values/CreateReservoir";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 仓库平面图显示API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoPrincipalShow(PrincipalShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/Warehouse/Ichnography?selectWarehouseArea=" + dto.selectWarehouseArea;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 仓库删除API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfowarehouseDelete(warehouseDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"]+ "mhb/api/Warehouse/WarehouseDelete";
            var respomse = await client.PostAsync(url, dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 仓库修改
        /// </summary>
        /// <returns></returns>
        public IActionResult warehouseUpdate()
        {
            return View();
        }
        /// <summary>
        /// 仓库反填API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfowarehouseFan(warehouseFanDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"]+ "mhb/api/Warehouse/WarehouseFan?warehouseID=" + dto.warehouseID;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 仓库修改API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfowarehouseUpdate(warehouseUpdateDTO obj1, string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url =_configuration["Url"]+ "mhb/api/Warehouse/WarehouseUpdate";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 仓库详情
        /// </summary>
        /// <returns></returns>
        public IActionResult ParticularsShowWarehouse()
        {
            return View();
        }
        /// <summary>
        /// 仓库详情API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoParticularsShowWarehouse(warehouseFanDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url =_configuration["Url"]+ "mhb/api/Warehouse/WarehouseFan?warehouseID=" + dto.warehouseID;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 仓库详情API（关联库区详情）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoParticularsShowReservoir(ParticularsShowReservoirDTO dto)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Values/ParticularsShowReservoir?pageIndex=" + dto.pageindex + "&pageSize=" + dto.pagesize + "&WarehouseID=" + dto.warehouseName;
            var response = await client.GetAsync(url);
            return Json(response);

        }
        /// <summary>
        /// 仓库详情API（关联库位详情）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoParticularsShowSupplier(ParticularsShowReservoirDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Location/ParticularsShowLocation?pageIndex=" + dto.pageindex + "&pageSize=" + dto.pagesize + "&WarehouseID=" + dto.warehouseName;
            var response = await client.GetAsync(url);
            return Json(response);
        }

        public async Task<ActionResult> WarehouseXlsx(ParticularsShowReservoirDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Location/ParticularsShowLocation?pageIndex=" + dto.pageindex + "&pageSize=" + dto.pagesize + "&WarehouseID=" + dto.warehouseName;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        


        /// <summary>
        /// 库区反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetReservoirId(ReservoirIdDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Values/GetReservoir?ReservoirId=" + dto.Id;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 库区修改
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="Token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UpdReservoir(ReservoirUpdaDto dto, string Token)
        {
            HttpClientWrapper client = new HttpClientWrapper(Token);
            string url = _configuration["Url"] + "LYH/api/Values/UpdateReservoir";
            string list = JsonConvert.SerializeObject(dto);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 库区删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> DelReservoir(ReservoirAddDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Values/DeleteReservoir";
            var list = "{\"reservoirId\":[" + dto.Data + "]}"; 
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 库位视图
        /// </summary>
        /// <returns></returns>
        public IActionResult LocationShow()
        {
            return View();
        }
        /// <summary>
        /// 库位管理显示列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> LocationShowsj(LocationDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Location/ShowLocation?pageIndex=" + dto.pageIndex + "&pageSize=" + dto.pageSize + "&LocationName=" + dto.locationName + "&LocationNumber=" + dto.locationNumber+"&LocationState="+dto.locationState;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 添加库位管理
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> LocationAdd(LocationAddDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Location/CreateLocation";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 库位反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetLocationId(ReservoirIdDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Location/GetLocation?LocationId=" + dto.Id;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 库位修改
        /// </summary>
        /// <param name="dto"></param>
        /// <param name="Token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UpdLocation(LocationUpDto dto, string Token)
        {
            HttpClientWrapper client = new HttpClientWrapper(Token);
            string url = _configuration["Url"] + "LYH/api/Location/UpdateLocation";
            string list = JsonConvert.SerializeObject(dto);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 库区删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> DelLocation(LocationAddDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "LYH/api/Location/DeleteLocation";
            var list = "{\"locationId\":[" + dto.Data + "]}";
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
    }
}
